package com.wutianyi.html.impl;

import org.htmlparser.Node;
import org.htmlparser.tags.TableColumn;
import org.htmlparser.tags.TableRow;

import com.wutianyi.dataobject.PostBean;
import com.wutianyi.html.InfoHandle;

public class Ip138PostHandle implements InfoHandle<PostBean[]> {

	@Override
	public PostBean[] handle(Node node) {
		if (node instanceof TableRow) {
			TableRow row = (TableRow) node;
			int columnSize = row.getColumnCount();
			TableColumn[] columns = row.getColumns();
			PostBean post1 = new PostBean();

			String name = null;
			if (4 == columnSize) {
				name = columns[0].getChild(0).getLastChild().getText().trim();
			} else {
				name = columns[0].getChild(0).getFirstChild().getText().trim();
			}
			post1.setName(name);
			post1.setPost(columns[1].getChild(0).getText().trim());
			post1.setZone(columns[2].getChild(0).getText().trim());

			if (4 == columnSize) {
				return new PostBean[] { post1 };
			}
			if (null == columns[3].getChild(0).getFirstChild()) {
				return new PostBean[] { post1 ,null};
			}
			PostBean post2 = new PostBean();
			post2.setName(columns[3].getChild(0).getFirstChild().getText()
					.trim());
			post2.setPost(columns[4].getChild(0).getText().trim());
			post2.setZone(columns[5].getChild(0).getText().trim());
			return new PostBean[] { post1, post2 };
		}

		return null;
	}

}
